package com.xx.gen1;

import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.springframework.lang.NonNull;

import java.io.File;
import java.util.Map;

/**
 * <p>
 * 对自定义的类处理，即other里生成的类
 * </p>
 *
 * @author xuyanqing
 * @since 2022-11-16 10:56:55
 */
public class EnhanceFreemarkerTemplateEngine extends FreemarkerTemplateEngine {

    @Override
    protected void outputCustomFile(Map<String, String> customFile, TableInfo tableInfo, @NonNull Map<String, Object> objectMap) {
        // objectMap 里的key可以在ftl文件中直接引用
        // https://copyfuture.com/blogs-details/20210404114118659h
        String entityName = tableInfo.getEntityName();
        String otherPath = this.getPathInfo(OutputFile.other);
        customFile.forEach((key, value) -> {
            // 拼接路径
            String fileName = String.format(otherPath + File.separator + entityName + "%s", key);
//            System.out.println(fileName);
            this.outputFile(new File(fileName), objectMap, value);
        });
    }
}
